#include "thermalcam.h"

int main(int argc, char* argv[])
{   
    if(argc != 2){
        printf("main argc error: != 2\n");
        return -1;
    }
    const string iniPath =  argv[1];

    //const string iniPath = "/home/ljl/Desktop/hck/thermal-hik/config/DeviceConfig.ini";  // argv[1];
    if(iniPath.find(".ini") == string::npos){
        printf("main input param error: ini path error--%s\n", iniPath.c_str());
        return -1;
    }
    bExitClient = false;
    //for run thermal camera
    thermal* thermal1 = NULL;
    try{
        thermal1 = new thermal(iniPath, "Robot001");;
        thermal1->mthermal = thermal1;
    }
    catch(string info){
        cout << info << endl;
        delete thermal1;
        return -1;
    }
    catch(...){
        printf("thermal() error!!!\n");
        delete thermal1;
        return -1;
    }

	if ( thermal1->mhckRun() == -1)
    {
        printf("thermal1->mhckRun  error\n");

        delete thermal1;
        thermal1 = NULL;
        return -1;
    }

    //for communication with linux
    thread clientToLinux_t(clientToLinux_thread, (void*)NULL);

    while (1)
    {
        printf("please input command:\n");
        mutexExitClient.lock();
        char exit = cin.get();
        
        if(exit == 'q'){
            bExitClient = true;
            mutexExitClient.unlock();
            break;
        }
        mutexExitClient.unlock();
    }

    printf("start join clientToLinux_t\n");
    if(clientToLinux_t.joinable()){
       clientToLinux_t.join();
       cout << "clientToLinux:: exit success" << endl;
    }

    printf("start delete thermal1\n");
    if(thermal1 != NULL){
        delete thermal1;
        thermal1 = NULL;
    }

    cout << "thermal camera exit successful" << endl;
    return 0;

}

